package com.peng.leetcode.slidingWindow;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * MaxSatisfied
 * <p>
 * 1052. 爱生气的书店老板
 *
 * @author: lupeng6
 * @create: 2021/2/23 11:13
 */
public class MaxSatisfied {

    public static void main(String[] args) {
        int[] customers = {1, 0, 1, 2, 1, 1, 7, 5}, grumpy = {0, 1, 0, 1, 0, 1, 0, 1};
        int X = 3;
//        int[] customers = {5, 8}, grumpy = {0, 1};
//        int X = 1;
        System.out.println(new MaxSatisfied().maxSatisfied(customers, grumpy, X));
    }


    public int maxSatisfied(int[] customers, int[] grumpy, int X) {
        int total = 0;
        for (int i = 0; i < customers.length; i++) {
            if (grumpy[i] == 0) {
                total += customers[i];
            }
        }

        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < customers.length; i++) {
            if (grumpy[i] == 1) {
                list.add(customers[i]);
            }
        }

        Collections.reverse(list);

        for (int i = 0; i < X; i++) {
            total += list.get(i);
        }

        return total;
    }
}
